# !/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import re
from modelEtl.modeBase import modeBase
import hashlib
from config import dmp
import requests
import json
from updateConf.borough import borough
from updateConf.cityArea import cityArea
import time

class dsp(modeBase):
    def __init__(self, source, data, redis):
        #data = self.ListDelNull(data)
        super(dsp, self).__init__()

        self.platform_type = data.get("platform_type")
        self.phone = data.get("username")  # 客源手机号
        self.house_id = data.get("house_id")
        self.purpose_desc = data.get("intention")
        self.source_id = source  # 数据来源
        self.city = data.get("city") # 客源所在城市
        self.page_type = "二手房"  # 房源类型（1：新房，2：二手房）【×】
        self.visit_time = self._visit_time(data=data.get("create_time"))  # 访问时间【×】
        self.house_city = data.get("city") #房源所在市【×】
        self.appName = data.get("appName")

        self.borough_id= data.get("borough_id")  # 小区名称
        self.borough_name = data.get("borough_name")  # 小区名称
        self.borough_name_source = data.get("borough_name")  # 小区名称
        self.house_price = self._house_price(data.get("intention_price")) #总价，单位万元(float, 2)
        self.cityarea2_id = data.get('cityarea2_id')
        self.cityarea2_name = data.get("cityarea2_name")
        self.cityarea2_name_source = data.get("cityarea2_name")
        self.cityarea_id = data.get("cityarea_id")
        self.cityarea_name = data.get('cityarea_name')
        self.cityarea_name_source = data.get('cityarea_name')

    def _visit_time(self, data):
        x = time.localtime(data)
        return time.strftime('%Y-%m-%d %H:%M:%S', x)

    def _house_price(self, data):
        if not data: return 0
        if data in ["不限"] : return -1

        prictArr = data.split('-')
        if len(prictArr) == 1: return data
        else:
            return (float(prictArr[0]) + float(prictArr[1])) / 2










